package com.zx.learn.flink.utils;

import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Ken.Zheng
 * @date 2023/06/03
 **/
public class NcSocketStreamTest {

    public static void main(String[] args) throws Exception {

        //获取执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //界面上指定参数(本地测试可以忽略，设置了默认值)
        final ParameterTool params = ParameterTool.fromArgs(args);
        String hostName = params.get("hostname", "localhost");
        int port = params.getInt("port", NcMockServer.PORT);

        //数据来源(获取sourceStream)
        DataStream<String> sourceStream = env.socketTextStream(hostName, port, "\n");

        //数据去向(打印到控制台)
        sourceStream.print();

        //执行
        env.execute("SocketStreamTest");
    }
}
